package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.Vo.HouseServiceOrderVo;
import com.jingjiu.homeservicesapi.domain.HouseServiceOrder;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.HouseServiceOrderServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 家政订单：记录家政服务的订单详情Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/Houseservice/order")
public class HouseServiceOrderController {

    @Autowired
    private HouseServiceOrderServiceImpl houseServiceOrderService;


    @GetMapping("/page")
    @ResponseBody
    public R<Page<HouseServiceOrderVo>> getPage(@ParameterObject Page<HouseServiceOrder> page,
                                                @ParameterObject  HouseServiceOrder houseServiceOrder) {
        Page<HouseServiceOrderVo> houseServiceOrderPage = houseServiceOrderService.selectPage(page, houseServiceOrder);
        if(houseServiceOrderPage==null)
            return R.failed();
        // 调用 Service 分页查询
        return R.ok(houseServiceOrderPage);
    }

    /**
     * 查询家政订单：记录家政服务的订单详情列表
     *//*

    @PostMapping("/list")
    @ResponseBody
    public Page list(HouseServiceOrder houseServiceOrder)
    {

        List<HouseServiceOrder> list = houseServiceOrderService.selectHouseServiceOrderList(houseServiceOrder);
        return null;
    }*/

 /*   *//**
     * 导出家政订单：记录家政服务的订单详情列表
     *//*

    @PostMapping("/export")
    @ResponseBody
    public R<List<HouseServiceOrder>> export(@RequestBody HouseServiceOrder houseServiceOrder)
    {
      return R.ok(houseServiceOrderService.selectHouseServiceOrderList(houseServiceOrder));
    }
*/

    /**
     * 新增保存家政订单：记录家政服务的订单详情
     */

    @PostMapping("/add")
    @ResponseBody
    public  R  addSave(@RequestBody HouseServiceOrder houseServiceOrder)
    {
        int row = houseServiceOrderService.insertHouseServiceOrder(houseServiceOrder);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }



    @GetMapping("/get/{id}")
    public R<HouseServiceOrderVo> getById(@PathVariable("id")Long id)
    {
        HouseServiceOrderVo houseServiceOrder = houseServiceOrderService.selectHouseServiceOrderById(id);
        if(houseServiceOrder==null)
            return R.failed();
        return  R.ok(houseServiceOrder);
    }


    @GetMapping("/getByUserId/{userId}")
    public R<List<HouseServiceOrderVo>> getByUserId(@PathVariable Long userId)
    {
        List<HouseServiceOrderVo> houseServiceOrder = houseServiceOrderService.selectHouseServiceOrderByUserId(userId);
        if(houseServiceOrder==null)
            return R.failed();
        return  R.ok(houseServiceOrder);
    }



    @GetMapping("/getByUserServerId/{userServerId}")
    public R<List<HouseServiceOrderVo>> getByUserServerId(@PathVariable Long userServerId)
    {
        List<HouseServiceOrderVo> houseServiceOrder = houseServiceOrderService.selectHouseServiceOrderByUserServerId(userServerId);
        if(houseServiceOrder==null)
            return R.failed();
        return  R.ok(houseServiceOrder);
    }

    /**
     * 修改保存家政订单：记录家政服务的订单详情
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody HouseServiceOrder houseServiceOrder)
    {
        int row = houseServiceOrderService.updateHouseServiceOrder(houseServiceOrder);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 删除家政订单：记录家政服务的订单详情
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int row = houseServiceOrderService.deleteHouseServiceOrderById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }
}
